package cn.tedu.spring.scope;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author ruoLi
 */
public class TestUser {
    ApplicationContext context=new ClassPathXmlApplicationContext("bean-scope.xml");
    @Test
    public void scopeTest(){
        //单实例
        User user1= context.getBean("user", User.class);
        User user2= context.getBean("user", User.class);
        System.out.println(user1);
        System.out.println(user2);
        if (user1==user2){
            System.out.println("相同对象");
            return;
        }
        System.out.println("不同对象");
    }
    @Test
    public void scopeTest2() {
        //多实例
        User user1= context.getBean("user1", User.class);
        User user2= context.getBean("user1", User.class);
        System.out.println(user1);
        System.out.println(user2);
        if (user1==user2){
            System.out.println("相同对象");
            return;
        }
        System.out.println("不同对象");
    }
}
